﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UploadController : ControllerBase
    {
        public UploadController(IWebHostEnvironment web)
        {
            Web = web;
        }

        public IWebHostEnvironment Web { get; }
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Upload(IFormFile file  )
        {
            string path=Web.WebRootPath + @"\imgs\";
            FileStream fs=System.IO.File.Create(path+file.FileName);
            file.CopyTo(fs);
            fs.Close();
            return Ok("/imgs/"+file.FileName);
        }



    }
}
